package com.macro.mall.portal.service.impl;

import java.util.List;
import java.util.Objects;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.macro.mall.dto.BmsMuseumDetail;
import com.macro.mall.dto.BmsMuseumParam;
import com.macro.mall.mapper.BmsMuseumMapper;
import com.macro.mall.model.BmsMuseum;
import com.macro.mall.model.BmsMuseumExample;
import com.macro.mall.portal.service.BmsMuseumPicService;
import com.macro.mall.portal.service.BmsMuseumService;

@Service
public class BmsMuseumServiceImpl implements BmsMuseumService {

    @Autowired
    private BmsMuseumMapper bmsMuseumMapper;

    @Autowired
    private BmsMuseumPicService bmsMuseumPicService;

    @Override
    public List<BmsMuseum> getList(BmsMuseumParam bmsMuseumParam) {
        Integer pageNum = bmsMuseumParam.getPageNum();
        Integer pageSize = bmsMuseumParam.getPageSize();
        if (Objects.nonNull(pageNum) && Objects.nonNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize);
        }
        BmsMuseumExample example = new BmsMuseumExample();
        BmsMuseumExample.Criteria criteria = example.createCriteria();
        criteria.andIsDeleteEqualTo((byte) 0);
        example.setOrderByClause("create_time desc");
        List<BmsMuseum> list = bmsMuseumMapper.selectByExample(example);
        return list;
    }

    @Override
    public BmsMuseumDetail getItem(Long id) {
        BmsMuseum bmsMuseum = bmsMuseumMapper.selectByPrimaryKey(id);
        BmsMuseumDetail detail = new BmsMuseumDetail();
        BeanUtils.copyProperties(bmsMuseum, detail);
        // 获取封面图
        String coverPic = bmsMuseumPicService.findCoverPicByMuseumId(bmsMuseum.getId());
        // 获取活动图片
        List<String> picList = bmsMuseumPicService.findPicListByMuseumId(bmsMuseum.getId());

        detail.setCoverPic(coverPic);
        detail.setPicList(picList);

        return detail;
    }

    @Override
    public List<BmsMuseum> findAllList() {
        return bmsMuseumMapper.findAllList();
    }

}
